<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="fragment :: common_head(~{::meta},~{::title},~{},~{::style},~{::script})">
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .list { display: inline-block;
            width: 200px; height: 50px; border: 1px solid #ccc;
            line-height: 50px; text-align: center;
            background-color: palevioletred; padding: 0 10px; margin-left: -4px;}
        .odd { background-color: antiquewhite;}
    </style>
    <script>
        $(function() {
            $('.delete').filter('a').click(function () {
                var url = $(this).attr('href');
                $('.delete').filter('form').attr('action', url).submit();
                return false;
            });
        });
    </script>
</head>
<body>
<header id="header" th:replace="fragment :: header"></header>
<div id="content">
    <h3>部门列表</h3>
    <!-- 转换 delete 请求 -->
    <form action="#" method="post" class="delete">
        <input type="hidden" name="_method" value="DELETE">
    </form>
    <ul>
        <li>
            <span class="list">部门编号</span>
            <span class="list">部门名称</span>
            <span class="list">部门描述</span>
            <span class="list">编辑</span>
            <span class="list">删除</span>
        </li>
        <li th:each="dept: ${departments}" >
            <span class="list" th:text="${dept.id}" th:classappend="${deptStat.odd} ? 'odd'"></span>
            <span class="list" th:text="${dept.name}" th:classappend="${deptStat.odd} ? 'odd'"></span>
            <span class="list" th:text="| ${dept.desc}|" th:classappend="${deptStat.odd} ? 'odd'"></span>
            <span class="list" th:classappend="${deptStat.odd} ? 'odd'">
                <a href="#" th:href="@{/chpt2/dept/{deptId}(deptId=${dept.id})}">编辑</a>
            </span>
            <span class="list" th:classappend="${deptStat.odd} ? 'odd'">
                <a class="delete" href="#" th:href="@{/chpt2/dept/{deptId}(deptId=${dept.id})}">删除</a>
            </span>
        </li>
    </ul>
    <a href="" th:href="@{/chpt2/dept}">添加部门</a>
</div>
<footer id="footer" th:replace="fragment :: footer"></footer>
</body>
</html>